brute force implementation *1100

Please click on ads to support us..

Python Code:

import sys, os
from io import BytesIO, IOBase
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from bisect import bisect_left as bl, bisect_right as br, bisect
from functools import lru_cache
import heapq
import math
from collections import OrderedDict
from collections import Counter
from itertools import combinations
from itertools import accumulate
import operator
import bisect
from collections import deque,defaultdict
import copy
from itertools import permutations
from operator import itemgetter
from functools import lru_cache
import bisect
 
 
BUFSIZE = 8192
 
class FastIO(IOBase):
    newlines = 0
 
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
 
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
 
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
 
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
 
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
 
stdin, stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) 
 
mod = pow(10, 9) + 7
mod2 = 998244353
        
def inp(): return stdin.readline().strip()
def iinp(): return int(inp())
def out(var, end="\n"): stdout.write(str(var)+"\n")
def outa(*var, end="\n"): stdout.write(' '.join(map(str, var)) + end)
def lmp(): return list(mp())
def mp(): return map(int, inp().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(m, val) for j in range(n)]
def ceil(a, b): return (a+b-1)//b
 
def bin(a,b):
    if b==0:
        return 1
    r=bin(a,b//2)
    if b%2:
        return r*r*a
    else:
        return r*r
 
def gcd(a,b):
    if a == 0:
        return b
    return gcd(b % a, a)

def lcm(a,b):
    return (a // gcd(a,b))* b
def check(m,a):
    for i in range(len(a)-1):
        if a[i]+m<a[i+1]:
            return False
    return  True


def solve(d):
    d[0][0]=(d[2][1]+d[1][2])//2
    d[-1][-1]=(d[1][0]+d[0][1])//2
    d[1][1]=(d[0][1]+d[2][1])//2
    for i in range(len(d)):
        for j in range(len(d)):
            print(d[i][j],end=" ")
        print()
'''    
t=iinp()
for i in range(t):
    n=iinp()
        a=lmp()
        solve(n,a)

'''
d=[]
for i in range(3):
    d.append(lmp())
solve(d)

C++ Code:

#include<bits/stdc++.h>
#define int long long
using namespace std ;

int32_t main() {
    int a00,a01,a02,a10,a11,a12,a20,a21,a22 ;
    cin>>a00>>a01>>a02>>a10>>a11>>a12>>a20>>a21>>a22 ; 
    int sum=(a01+a02+a10+a12+a20+a21)/2 ;
    a00=sum-(a01+a02) ;
    a11=sum-(a10+a12) ;
    a22=sum-(a20+a21) ;
    cout<<a00<<" "<<a01<<" "<<a02<<endl ;
    cout<<a10<<" "<<a11<<" "<<a12<<endl ;
    cout<<a20<<" "<<a21<<" "<<a22<<endl ;
     
    return 0 ;
}


Comments

Submit
0 Comments
More Questions

1560C - Infinity Table
1605C - Dominant Character
1399A - Remove Smallest
208A - Dubstep
1581A - CQXYM Count Permutations
337A - Puzzles
495A - Digital Counter
796A - Buying A House
67A - Partial Teacher
116A - Tram
1472B - Fair Division
1281C - Cut and Paste
141A - Amusing Joke
112A - Petya and Strings
677A - Vanya and Fence
1621A - Stable Arrangement of Rooks
472A - Design Tutorial Learn from Math
1368A - C+=
450A - Jzzhu and Children
546A - Soldier and Bananas
32B - Borze
1651B - Prove Him Wrong
381A - Sereja and Dima
41A - Translation
1559A - Mocha and Math
832A - Sasha and Sticks
292B - Network Topology
1339A - Filling Diamonds
910A - The Way to Home
617A - Elephant